package com.lzz.bottomencapsulation.utils;

import android.app.Application;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.os.Build;
import androidx.core.app.NotificationCompat;
/***
 @package ${package}
 @filename ${适配8.0 通知渠道}
 */
public class Notification8 {
    static  Notification8 notification8;
    String CHANNEL_NEWS="CHANNEL_NEWS";
    String CHANNEL_ADS="CHANNEL_ADS";
    public static Notification8 getInstance() {
        if (notification8==null){
            notification8=new Notification8();
        }
        return notification8;
    }
    public void  init(Application application){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel newsChannel = new NotificationChannel(CHANNEL_NEWS, "新闻",
                    NotificationManager.IMPORTANCE_HIGH);
            NotificationChannel adsChannel = new NotificationChannel(CHANNEL_ADS, "广告",
                    NotificationManager.IMPORTANCE_DEFAULT);
            NotificationManager manager = (NotificationManager) application.getSystemService(Context.NOTIFICATION_SERVICE);
            manager.createNotificationChannel(newsChannel);
            manager.createNotificationChannel(adsChannel);
        }
    }



    public void sendNews(Context context,String title ,String content,int id) {

        NotificationManager manager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
        Notification notification = new NotificationCompat.Builder(context, CHANNEL_NEWS)
                .setContentTitle(title)
                .setContentText(content)
                .setAutoCancel(true)
                .build();
        manager.notify(id, notification);
    }

    public void sendAds(Context context,String title ,String content,int id) {
        NotificationManager manager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
        Notification notification = new NotificationCompat.Builder(context, CHANNEL_ADS)
                .setContentTitle(title)
                .setContentText(content)
                .setAutoCancel(true)
                .build();
        manager.notify(id, notification);
    }

    public void sendNoChannel(Context context,String title ,String content,int icon) {
        NotificationManager manager = (NotificationManager)context. getSystemService(context.NOTIFICATION_SERVICE);
        Notification notification = new NotificationCompat.Builder(context)
                .setContentTitle(title)
                .setContentText(content)
                .setAutoCancel(true)
                .setSmallIcon(icon)
                .build();
        manager.notify(1, notification);
    }


}
